/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.uefs.cedoc.controle.estante;

import br.uefs.cedoc.controle.Command;
import br.uefs.cedoc.controle.CommandException;
import br.uefs.cedoc.controle.CommandToken;
import br.uefs.cedoc.db.estante.DBEstante;
import br.uefs.cedoc.entidades.EstanteBean;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author suporte
 */
public class DeleteEstanteCommand implements Command {

    private String next;

    public DeleteEstanteCommand(String next) {
        this.next = next;
    }

    public String execute(HttpServletRequest req)
            throws CommandException {
        try {
            if (CommandToken.isValid(req)) {
                DBEstante dbestante = new DBEstante();
                EstanteBean estante = new EstanteBean();
                int id = Integer.parseInt(req.getParameter("id"));
                dbestante.removerEstante(id);
                req.setAttribute("status.msg", "Estante deletado!");
            } else {
                req.setAttribute("status.msg", "Nao foi possivel deletar!");
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        } 
        return next;

    }
}

